//
//  DBOxygen.m
//  CareRingApp
//
//  Created by Linktop on 2022/6/7.
//

#import "DBOxygen.h"
#import "DBHistoryDataSr03.h"


NSString * const TABLE_NM_OXYGEMN = @"table_oxygen";

@implementation DBOxygen



+(void)query:(NSString * _Nonnull)macAddress Begin:(NSTimeInterval)beginTime   End:(NSTimeInterval)endTime Desc:(BOOL)isDesc  Cpmplete:(void(^)(NSMutableArray<DBOxygen *> * results) )cmpBlk
{
   
    
    if (!macAddress.length) {
        return;
    }
    
    [DBHistoryDataSr03 queryBy:macAddress Begin:[NSDate dateWithTimeIntervalSince1970:beginTime] End:[NSDate dateWithTimeIntervalSince1970:endTime] OrderBeTimeDesc:isDesc Cpmplete:^(NSMutableArray<DBHistoryDataSr03 *> * _Nonnull results) {
        
        NSMutableArray<DBOxygen *> *oxygenRes = [NSMutableArray new];
        for (DBHistoryDataSr03 *hisObj in results) {
            
            if (hisObj.bloodOxygen.intValue > 80 && hisObj.bloodOxygen.intValue <= 100) {
                DBOxygen *oxygenModel = [[DBOxygen alloc]init];
                
                oxygenModel.value = hisObj.bloodOxygen;//@([rs doubleForColumn:@"value"]);
                oxygenModel.time = [NSDate dateWithTimeIntervalSince1970:hisObj.time.doubleValue];//[rs dateForColumn:@"time"];
                oxygenModel.macAddress = macAddress;//[rs stringForColumn:@"account"];
                oxygenModel.battery = hisObj.battery;
                
                [oxygenRes addObject:oxygenModel];
            }
           
        }
        
        if (cmpBlk) {
            dispatch_async(dispatch_get_main_queue(), ^{
                cmpBlk(oxygenRes);
            });
        }
        
    }];
    
}




@end
